// import {
// 	completeAdd,
// 	select,
// 	getComplete
// 	} from '@/src/api/user.js'
// import cropper from "@/src/components/lxiaoxiao-cropper/index.vue";
import * as index from '@/api/index.js'
import * as resume from '@/api/resume.js'
import * as user from '@/api/user.js'
import ImageCropper from "@/components/invinbg-image-cropper/index.vue";
import {
	baseURL
} from '@/common/config.js'
export default {
	components: {
		ImageCropper
	},
	data() {
		return {
			tempFilePath: '',
			form: {},
			avatar: '/static/user/add.png',
			gender: [{
					name: '先生',
					type: '1',
					color: '#80DCF3'
				},
				{
					name: '女士',
					type: '0',
					color: '#fe7da4'
				}
			],
			drving_arr: [], //学历列表
			age_arr: [], //需求年限
			headList:[],//默认头像
		}
	},
	onLoad() {
		this.getDrvingList()
		this.getAgeList()
		this.getMemberResumeInfo()
		this.getHeadsList()
	},
	created() {

	},
	methods: {
		//不知道有什么用
		myUpload(rsp) {
			console.log(rsp, 'rsp');
			this.from.head = rsp.photoUrl;
		},
		//选择图片
		upload() {
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['original'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['camera','album'], //从相册选择
				success: (res) => {
					this.tempFilePath = res.tempFilePaths[0]
				}
			});
		},
		//裁剪图片
		confirm(e) {
			let token = uni.getStorageSync('token')
			let that = this
			this.tempFilePath = ''
			uni.uploadFile({
				url: baseURL+'zp_common_v1/upload',
				filePath: e.detail.tempFilePath,
				name: 'file',
				header: {
					//#ifdef APP-PLUS
					'type': 1,
					//#endif
					'Content-type': 'application/json',
					'token': token
				}, 
				success: (res) => {
					console.log(token,'token');
					console.log(res,'resss');
					if(res.code == 1){
						that.form.head = JSON.parse(res.data).data.fullurl
						that.close()
					} else {
						uni.showToast({
							title: res.msg
						})
					}
				}
			});
		},
		//必须单挂
		cancel() {
			console.log('canceled')
		},
		//默认头像列表
		getHeadsList(){
			user.getHeadsList().then(res=>{
				this.headList = res.data
			})
		},
		//获取个人资料
		getMemberResumeInfo() {
			resume.getMemberResumeInfo().then(res => {
				this.form = res.data
			})
		},
		//获取学历
		getDrvingList() {
			index.getDrvingList().then(res => {
				this.drving_arr = res.data
			})
		},
		//获取经验
		getAgeList() {
			index.getAgeList().then(res => {
				this.age_arr = res.data
			})
		},
		//性别点击
		genderClick(item, index) {
			this.form.gender = item.type
		},
		//出生时间选择
		bindDateChange(e) {
			this.form.date_date = e.detail.value
		},
		//最高学历选择
		drivingChange(e) {
			this.form.drving = this.drving_arr[e.detail.value].id
		},
		ageChange(e) {
			this.form.age = this.age_arr[e.detail.value].id
		},
		//提交
		submit() {
			var reg = /^[a-zA-Z\u4e00-\u9fa5]+$/;
			if(reg.test(this.form.name)) {
                   
                } else {
                    uni.showToast({
                    	icon: 'none',
                    	title: '请输入正确的姓名',
                    	duration: 2000
                    });
                    return;
                }
			if (this.form.name.length < 2) {
				uni.showToast({
					icon: 'none',
					title: '姓名最少两个字',
					duration: 2000
				});
			} else {
				this.form.edit = 'grzl'
				this.form.date = this.form.date_date
				resume.editMemberResume(this.form).then(res => {
					uni.showToast({
						icon: 'none',
						title: res.msg,
						duration: 2000
					});
					setTimeout(() => {
						this.$tools.back(1)
					}, 1500)
				})
			}

		},
		//汉字
		// input(event) {
		// 	var value = event.detail.value;
		// 	if (!value || value == " ") {
		// 		return '';
		// 	}
		// 	const rule = /[^\u4E00-\u9FA5]/g;
		// 	this.$nextTick(function() {
		// 		this.form.name = value.replace(rule, '');
		// 	})
		// },
		openPopup() {
			this.$refs.popup.open()
		},
		close() {
			this.$refs.popup.close()
		},
		closeAvatar(){
			this.$refs.avatar.close()
		},
		//打开默认头像
		getUserAvatar(){
			this.close()
			this.$refs.avatar.open()
		},
		//选择默认头像
		choseAvatar(item){
			this.form.head = item
			this.$refs.avatar.close()
		}
	}
}
